// 独立拆分并集中管理跟用户操作业务相关的网络请求
import request from '../utils/request'

// 验证token
export const checkToken = async (token) => {
    return request.get('/users/auth', {
        headers: {
            "token": token
        }
    })
}
// 登录
export const userLoginApi = async (payload) => {
    return request.get('/users',{
        params:payload
    })
}
// 注册
export const userRegApi = async (payload) => {
    return request.post('/users',payload)
}

// 信息更新
export const updateUserInfoApi = async (jwttoken,_id, payload) => {
    console.log(222,_id,payload);
    return request.put('/users',payload, {
        params:{id:_id},
        headers: {
            "token": jwttoken
        }
    })
}
// 上传图片
export const updateAvatarApi = async(payload) => {
    return request.post('/upload',{
        params:{
            'avatar':payload
        }
    })
}
// 信息更新
export const userUpdateApi = async (id,payload) => {
    return request.put('/users',payload,{
        params:{id}
    })
}

//role
// 角色新增
export const flyrolePostApi = async (payload) => {
    return request.post('/flyrole',payload)
}

// 角色查询
export const flyroleGetApi = async (roleId) => {
    let params = roleId ? {'id':roleId} : {}
    return request.get('/flyrole',{
        params
    })
}
// 角色更新
export const flyroleUpdateApi = async (id,payload) => {
    return request.put('/flyrole',payload,{
        params:{id}
    })
}
// 角色删除
export const flyroleDeleteApi = async (id) => {
    return request.delete('/flyrole',{
        params:{id}
    })
}